package com.dhms.vostok1.network

import com.dhms.lib.utils.MkvSharedPreferences
import okhttp3.Interceptor
import okhttp3.Response
import java.util.*

class RequestInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val builder = request.newBuilder()
        // 这里添加公共请求头
        builder.addHeader("X-Request-Id", UUID.randomUUID().toString())

        val token = MkvSharedPreferences.getValue("token")
        val organizationId = MkvSharedPreferences.getValue("organization_id",0L)
//        println("dhmsZToken:"+token)
//        println("dhmsZOrganizationId:"+organizationId)
        if (token != null && token.isNotEmpty()) {
            builder.addHeader("X-Auth-Tkn", token)
        }
        if (organizationId != 0L) {
            builder.addHeader("X-Forwarded-PrId", "-1")
            builder.addHeader("X-Forwarded-OrgSet", organizationId.toString())
        }

        return chain.proceed(builder.build())
    }
}